<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        position: absolute;
        left: 0;
        top: 0;
        width: 100px;
        height: 100px;
        background-color: orange;
      }
      span {
        position: absolute;
        left: 300px;
        top: 0;
        background-color: black;
        width: 1px;
        height: 100px;
      }
    </style>
  </head>
  <body>
    <div></div>
    <span></span>
    <script>
      const divEl = document.querySelector("div");
      divEl.onclick = function () {
        startMove(this, 300);
      };

      function startMove(domEl, target) {
        clearInterval(domEl.timer);
        let a = 3;
        let iSpeed = 0;
        const u = 0.8;
        domEl.timer = setInterval(() => {
          a = (target - domEl.offsetLeft) / 5;
          iSpeed += a;
          iSpeed *= u;
          if (Math.abs(iSpeed) < 1 && Math.abs(target - domEl.offsetLeft) < 1) {
            clearInterval(domEl.timer);
            domEl.timer = null;
            domEl.style.left = target + "px";
          } else {
            domEl.style.left = domEl.offsetLeft + iSpeed + "px";
          }
        }, 30);
      }
    </script>
  </body>
</html>
